import {createRouter, createWebHistory} from "vue-router";
import routes from "./routesConfig"

const Router = createRouter({
    history: createWebHistory(),
    routes: routes
});

//路由守卫动态合并设置国际化messages
const setDm18nMessage = function({i18n}){
    if(!i18n) return;
    for(let key in i18n){
        let messages = window.$dm18n.messages[key];
        if(messages){
            Object.assign(messages, i18n[key]) 
        }else{
            window.$dm18n.messages[key] = i18n[key]
        }
    }
}

Router.beforeEach((to, from, next)=>{
    setDm18nMessage(to.meta);
    next()
})

export default Router;